#ifndef MYTIMER_H
#define MYTIMER_H

#include <QWidget>
#include <QTimer>
#include <QPropertyAnimation>

class MyTimer : public QWidget
{
    Q_OBJECT
    Q_PROPERTY(int progress READ progress WRITE setProgress)
public:
    explicit MyTimer(QWidget *parent = nullptr);

    void mousePressEvent(QMouseEvent *event) override {emit clicked();}
    void paintEvent(QPaintEvent *event) override;

    void set_duration(int dur);
    void set_lap(int lap) { this->lap = lap; repaint(); }
    void start() {timer.start();}
    void pause() {timer.stop();}

    int progress() {return current;}
    void setProgress(int progress) {current = progress;}

private:
    QString formated_current() const {
        int temp = current % (60*60);
        return QString("%1:%2").arg(QString::number(temp/60).rightJustified(2, '0'))
                               .arg(QString::number(temp%60).rightJustified(2, '0'));
    }

signals:
    void clicked();
    void time_up();

private:
    QTimer timer;

    int duration = 1;  // SECONDS
    int current = 1;  // SECONDS
    int lap = 1;

    QPropertyAnimation *anim;
};

#endif // MYTIMER_H
